package com.gwnet.shop.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.gwnet.common.log.annotation.Log;
import com.gwnet.common.log.enums.BusinessType;
import com.gwnet.common.mybatis.core.page.TableDataInfo;
import com.gwnet.shop.domain.UserCollectGoods;
import com.gwnet.shop.service.IUserCollectGoodsService;
import com.gwnet.shop.utils.AjaxResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户收藏店铺Controller
 * 
 * @author 张万鹏
 * @date 2024-08-01
 */
@RestController
@RequestMapping("/collectgoods")
public class UserCollectGoodsController extends MBaseController
{
    @Resource
    private IUserCollectGoodsService userCollectGoodsService;

    /**
     * 查询用户收藏店铺列表
     */
    @SaCheckPermission("shop:collectGoods:list")
    @GetMapping("/list")
    public TableDataInfo list(UserCollectGoods userCollectGoods)
    {
        startPage();
        List<UserCollectGoods> list = userCollectGoodsService.selectUserCollectGoodsList(userCollectGoods);
        return getDataTable(list);
    }


    /**
     * 获取用户收藏店铺详细信息
     */
    @SaCheckPermission("shop:collectGoods:query")
    @GetMapping
    public AjaxResult getInfo(UserCollectGoods userCollectGoods)
    {
        return success(userCollectGoodsService.selectUserCollectGoodsByUserIdAndGoodsId(userCollectGoods));
    }

    /**
     * 新增用户收藏店铺
     */
    @SaCheckPermission("shop:collectGoods:add")
    @Log(title = "用户收藏店铺", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserCollectGoods userCollectGoods)
    {
        return toAjax(userCollectGoodsService.insertUserCollectGoods(userCollectGoods));
    }


    /**
     * 删除用户收藏店铺
     */
    @SaCheckPermission("shop:collectGoods:remove")
    @Log(title = "用户收藏店铺", businessType = BusinessType.DELETE)
	@DeleteMapping
    public AjaxResult remove(@RequestBody UserCollectGoods userCollectGoods)
    {
        return toAjax(userCollectGoodsService.deleteUserCollectGoodsByUserIdAndGoodsId(userCollectGoods));
    }
}
